package com.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.ReplyBean;
import com.project.bean.StickBean;
import com.project.mapper.IReplyMapper;
import com.project.mapper.IStickMapper;
import com.project.mapper.IUserMapper;
import com.project.service.IStickService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class StickServiceImpl implements IStickService {
    @Autowired
    private IStickMapper mapper;
    @Autowired
    private IUserMapper userMapper;
    @Autowired
    private IReplyMapper replyMapper;
    @Override
    public IPage<StickBean> findByItem(Integer pageNO, Integer channelId, String title, String name, LocalDate startDate, LocalDate endDate) {
        return mapper.findByItem(new Page(pageNO,3),channelId,title,name,startDate,endDate);
    }

    @Override
    public void add(StickBean stick) {
        mapper.insert(stick);
    }

    @Override
    public StickBean findById(Integer stickId) {
        StickBean stickBean = mapper.selectById(stickId);
        stickBean.setUser(userMapper.findById(stickId));
        stickBean.setReplyList(replyMapper.findById(stickId));
        return stickBean;
    }
}
